package com.goodedeeds.webapp.controller;

import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;
import net.sourceforge.stripes.validation.SimpleError;
import net.sourceforge.stripes.validation.Validate;

/**
 * Created by IntelliJ IDEA.
 * User: ravi
 * Date: 8/12/12
 * Time: 10:58 PM
 * To change this template use File | Settings | File Templates.
 */
@UrlBinding(ChangePasswordAction.URL)
public class ChangePasswordAction extends BaseDashboardAction {
    public static final String URL = "/change-password.action";

    private static final String DASHBOARD_CONTENT = JSP_ROOT + "/change-password.jsp";

    @Validate(on="changePassword", required = true)
    private String currentPassword;

    @Validate(on="changePassword", required = true)

    private String newPassword;

    @Validate(on="changePassword", required = true)
    private String newPassword2;

    /* (non-Javadoc)
      * @see com.depo.quiggle.view.controller.BaseDashboardAction#getDashboardContent()
      */
    @Override
    public String getDashboardContent() {
        return DASHBOARD_CONTENT;
    }

    @Override
    public DashboardTab getCurrentTab() {
        return null;
    }

    @Override
    public ISubTab getCurrentSubTab() {
        return null;
    }

    private Boolean success;

    public Resolution changePassword(){
        if(!newPassword2.equals(newPassword)){
            addValidationError("newPassword", new SimpleError("New Password and Retype New Password Doesn't match."));
            addValidationError("newPassword2", new SimpleError(""));
            return showPage();
        }
//        success = AuthDaoFactory.getAuthenticationDao().changePassword(getAuthUser().getUserId(), currentPassword, newPassword);

        if(!success){
            addGlobalError(new SimpleError("Password cannot be changed. Given password doesn't match our records!!"));
            return showPage();
        }

        return new RedirectResolution("");
    }

    public Boolean getSuccess() {
        return success;
    }

    public String getCurrentPassword() {
        return currentPassword;
    }

    public void setCurrentPassword(String currentPassword) {
        this.currentPassword = currentPassword;
    }

    public String getNewPassword() {
        return newPassword;
    }

    public void setNewPassword(String newPassword) {
        this.newPassword = newPassword;
    }

    public String getNewPassword2() {
        return newPassword2;
    }

    public void setNewPassword2(String newPassword2) {
        this.newPassword2 = newPassword2;
    }
}
